<template>
	<view id="evaluate" class="evaluate-container">
		<view class="evaluate" @click="goPage('/pages/order/evaluate/evaluate?productId=' + productId)">
			<view class="header">
				<view class="title">评价</view>
				<view class="count">
					<text>{{ formatNum(total) }}条评价</text>
					<u-icon class="arrow-right-icon" name="arrow-right" color="#242424"></u-icon>
				</view>
			</view>
			<view v-if="commentList.length" class="list">
				<view class="item" v-for="item in commentList" :key="item.id">
					<view class="user">
						<u-avatar size="48rpx" :src="item.avatar"></u-avatar>
						<text class="nickname">{{ maskPhoneNumber(item.nickName) || '用户昵称' }}</text>
					</view>
					<view class="content">{{ comment(item.comment, item.pics) }}</view>
					<view class="maps">
						<image :class="['image', index < 3 && 'mt0']" v-for="(src, index) in maps(item.pics)" :key="src" :src="src"></image>
					</view>
				</view>
			</view>
			<view v-else class="empty">此商品还没有人评价哦~</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, computed, onBeforeMount } from 'vue';
	import { goPage } from '@/utils';
	import { formatNum, maskPhoneNumber } from '@/utils';
	// import { orderComment } from '../service';
	
	const props = defineProps({
		productId: {
			type: [Number, String],
			default: '',
		},
	});
	// 评价列表
	const commentList = ref([]);
	// 总条数
	const total = ref<number>(0);
	// 获取评价列表
	const getOrderComment = (): void => {
		const params = {
			pageNum: 1,
			pageSize: 2,
			productId: props.productId,
		};
		// orderComment(params).then(res => {
		// 	if (res.code === 200) {
		// 		commentList.value = res.rows;
		// 		total.value = res.total;
		// 	}
		// });
	};
	// 评价内容
	const comment = computed(() => {
		return function(comment: string, pics: string) {
			if (comment) {
				return comment;
			}
			if (!comment && !pics) {
				return '此用户没有做出评价！'
			}
			return '';
		}
	});
	// 评价图片列表
	const maps = computed(() => {
		return function(pics: string) {
			return pics ? pics.split(',') : [];
		}
	});
	
	onBeforeMount(getOrderComment);
</script>

<style lang="scss" scoped>
	.evaluate-container {
		padding-top: 24rpx;
		.empty {
			height: 160rpx;
			line-height: 160rpx;
			font-size: 24rpx;
			color: #707070;
			text-align: center;
			background-color: #fff;
		}
	}
	.evaluate {
		background-color: #fff;
		.header {
			display: flex;
			justify-content: space-between;
			border-bottom: 1rpx solid #EEEEEE;
			padding: 24rpx 30rpx 24rpx 24rpx;
			.title {
				line-height: 32rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #242424;
			}
			.count {
				height: 32rpx;
				display: flex;
				align-items: center;
				text {
					line-height: 32rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #242424;
					margin-right: 22rpx;
				}
				.arrow-right-icon {
					margin-top: 4rpx;
				}
			}
		}
		.list {
			padding: 28rpx 24rpx 0;
			.item {
				padding-bottom: 50rpx;
				.user {
					display: flex;
					align-items: center;
					margin-bottom: 12rpx;
					.nickname {
						line-height: 24rpx;
						font-size: 24rpx;
						font-weight: 400;
						color: #000000;
						margin-left: 15rpx;
					}
				}
				.content {
					font-size: 24rpx;
					font-weight: 400;
					color: #242424;
					line-height: 36rpx;
					padding: 0 14rpx 0 66rpx;
					margin-bottom: 15rpx;
				}
				.maps {
					padding-left: 68rpx;
					.image {
						width: 200rpx;
						height: 200rpx;
						background: #D8D8D8;
						border-radius: 10rpx;
						margin: 16rpx 16rpx 0 0;
						&:nth-child(3n) {
							margin-right: 0;
						}
					}
					.mt0 {
						margin-top: 0 !important;
					}
				}
			}
		}
	}
</style>